package com.fh.rolemenu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fh.result.ResultObject;
import com.fh.rolemenu.entity.UmsRoleMenu;
import com.fh.rolemenu.service.IUmsRoleMenuService;
import com.fh.search.MenuToUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author F
 * @since 2021-05-17
 */
@RestController
@RequestMapping("/ums/rolemenu")
public class UmsRoleMenuController {


    @Autowired
    private IUmsRoleMenuService iUmsRoleMenuService;



    @PostMapping
    public ResultObject SaveMenuToUser(@RequestBody MenuToUser menuToUser){
        iUmsRoleMenuService.SaveMenuToUser(menuToUser);
        return ResultObject.success();
    }
    @GetMapping("{userId}")
    public ResultObject queryMenuByUser(@PathVariable("userId") Long userId){
        QueryWrapper<UmsRoleMenu> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("role_id",userId);
        queryWrapper.select("menu_id");
        List<UmsRoleMenu> list= iUmsRoleMenuService.list(queryWrapper);
        List<Long> MenuList=list.stream().map(x->x.getMenuId()).collect(Collectors.toList());
        return ResultObject.success(MenuList);
    }

}
